require ("XMLParser")
require ("StageParser")

GraphmlStageParser = class("GraphmlStageParser", StageParser)

---

function GraphmlStageParser:initialize(fileName)

	self.xmlParser = XMLParser:new(fileName .. ".graphml")
	
	--self.xmlParser:printData()
	
	self:parseRooms()
	self:parseDoors()
	self:createKeys()	
end

---

function GraphmlStageParser:parseRooms()

	local nodes = self.xmlParser:getSubTables(false, "node")
	
	self.nodesLabelByID = {}
	 
	for i, node in pairs(nodes) do
	
		local nodeLabel = self.xmlParser:getProperty(node, "y:NodeLabel")
	
		self.nodesLabelByID[self.xmlParser:getProperty(node, "id")] = nodeLabel
		
		local room = gField.world:addLocation(nodeLabel, "Room")
	end
end

---

function GraphmlStageParser:parseDoors()

	local edges = self.xmlParser:getSubTables(false, "edge")
	
	for i, edge in pairs(edges) do
	
		local edgeSource = self.xmlParser:getProperty(edge, "source")
		local edgeTarget = self.xmlParser:getProperty(edge, "target")
		
		self:addDoor(
			self.nodesLabelByID[edgeSource],
			self.nodesLabelByID[edgeTarget],
			self.xmlParser:getProperty(edge, "type") == "dashed"
		)
	end
end